<?php
namespace Admin\Controller;

use Common\Controller\AdminbaseController;

class LogsController extends AdminbaseController{

	protected $admin_log_model,$home_log_model,$member_log_model;

	public function _initialize() {
		C("SP_ADMIN_DEFAULT_THEME","tciocEx");
		parent::_initialize();
		$this->admin_log_model=M("logs_admin");
		$this->home_log_model=M("logs_home");
		$this->member_log_model=M("logs_member");
	}

    public function test(){
        $lists=array(
            array(
                "logid"=>1,
                "querystring"=>"牙体修复中聚氨酯弹性层的构建",
                "username"=>"朱松",
                "desc"=>"58万",
                "ip"=>"相对论、引力与宇宙学",
                "agent"=>"81671033",
                "time"=>"吉林大学",
                "type"=>"面上项目",
                "cid"=>"口腔颅颌面科学",
            ),
            array(
                "logid"=>2,
                "querystring"=>"婴幼儿口腔与肠道微生物群生物相关性研究",
                "username"=>"周学东",
                "desc"=>"56万",
                "ip"=>"污染物区域空间过程与生态风险",
                "agent"=>"81670978",
                "time"=>"四川大学",
                "type"=>"面上项目",
                "cid"=>"口腔颅颌面科学",
            ),
            array(
                "logid"=>3,
                "querystring"=>"慢性牙周炎和阿尔茨海默病的相关性研究：淀粉样前体蛋白及代谢物的双向调节作用初探",
                "username"=>"周薇",
                "desc"=>"58万",
                "ip"=>"新概念、新原理、新方法",
                "agent"=>"81670992",
                "time"=>"上海交通大学",
                "type"=>"面上项目",
                "cid"=>"口腔颅颌面科学",
            ),
            array(
                "logid"=>4,
                "querystring"=>"TGF-β1/TβR-Ⅰ、TβR-Ⅱ信号轴与骨形成改建的相关性分析及PNS 对牵张成骨骨愈合影响机制",
                "username"=>"周诺",
                "desc"=>"50万",
                "ip"=>"生物数据分析",
                "agent"=>"81670970",
                "time"=>"广西医科大学",
                "type"=>"面上项目",
                "cid"=>"口腔颅颌面科学",
            ),
            array(
                "logid"=>5,
                "querystring"=>"慢性牙周炎和阿尔茨海默病的相关性研究：淀粉样前体蛋白及代谢物的双向调节作用初探",
                "username"=>"周薇",
                "desc"=>"58万",
                "ip"=>"新概念、新原理、新方法",
                "agent"=>"81670992",
                "time"=>"上海交通大学",
                "type"=>"面上项目",
                "cid"=>"口腔颅颌面科学",
            ),
        );
        $page=$this->page(100,20);
        $this->assign("page",$page->show("tciocEx"));
        $this->assign("lists",$lists);
        $this->display("test");
    }

	// 日志列表
	public function index(){
		$model=I("model/s","admin");
        $search=I("s/s","");
		$sms_status=false;
        $where=array();
        if(trim($search)!==""){
            $where['querystring']=array("like","%$search%");
            $where['username']=array("like","%$search%");
            $where['desc']=array("like","%$search%");
            $where['ip']=array("like","%$search%");
            $where['agent']=array("like","%$search%");
            $where['_logic'] = 'or';
        }
        $model=strtolower($model);
        $models=C("LOGS_MODELS");
		//默认为admin
		(!in_array($model,$models)) && $model="admin";

		$logModel=M("logs_".$model);
		//如果是查看短信记录，则检查是否开启了短信
		$option=D("Common/Options")->where(array("option_name"=>"sms_settings"))->find();
		$sms_conf=json_decode($option['option_value'],true);
		if(isset($sms_conf['status'])&&$sms_conf['status']==1){
			$sms_status=true;
		}

		$count=$logModel->where($where)->count();
		$page=$this->page($count,20);
		$lists=$logModel->where($where)->order(" time desc ")->limit($page->firstRow,$page->listRows)->select();

		$this->assign("page",$page->show("tciocEx"));
		$this->assign("lists",$lists);
		$this->assign("sms_status",$sms_status);
		$this->assign("model",$model);
		$this->assign("s",$search);

		$this->display("index");
	}

}